<?php


class wvcrOptions{

	var $ID;
	var $data = array();
	
	function wvcrOptions()
	{
		global $wvcr;
		
		$this->ID = intval($_REQUEST['post']) > 0 ? intval($_REQUEST['post']) : 0;
		
		if ( ! $this->ID ) {
			if (isset($_POST['submit'])) {
				$this->data['notice'] = __('Error occurs. Please, try again!');
			}
			
			$wvcr->render('options', $this->data);
			exit();
		} else {
			if (isset($_POST['submit'])) {
				
				$border_color = $_POST['border_color'];
				$bg_color = $_POST['bg_color'];
				$text_color = $_POST['text_color'];
				$code_color = $_POST['code_color'];
				$code_bg_color = $_POST['code_bg_color'];
				$width = $_POST['width'];
				
				update_post_meta($this->ID, 'border_color', $border_color);
				update_post_meta($this->ID, 'bg_color', $bg_color);
				update_post_meta($this->ID, 'text_color', $text_color);
				update_post_meta($this->ID, 'code_color', $code_color);
				update_post_meta($this->ID, 'code_bg_color', $code_bg_color);
				update_post_meta($this->ID, 'width', $width);
				
				$this->data['message'] = __('Options saved!');
			}
			
			$this->data['border_color'] = get_post_meta($this->ID, 'border_color', 1) == '' ? '004080' : get_post_meta($this->ID, 'border_color', 1);
			$this->data['bg_color'] = get_post_meta($this->ID, 'bg_color', 1) == '' ? 'cce3ff' : get_post_meta($this->ID, 'bg_color', 1);
			$this->data['text_color'] = get_post_meta($this->ID, 'text_color', 1) == '' ? 'CC0066' : get_post_meta($this->ID, 'text_color', 1);
			$this->data['code_color'] = get_post_meta($this->ID, 'code_color', 1) == '' ? '0000ff' : get_post_meta($this->ID, 'code_color', 1);
			$this->data['code_bg_color'] = get_post_meta($this->ID, 'code_bg_color', 1) == '' ? 'ffff00' : get_post_meta($this->ID, 'code_bg_color', 1);
			$this->data['width'] = get_post_meta($this->ID, 'width', 1) == '' ? '500px' : get_post_meta($this->ID, 'width', 1);
			
			query_posts("post_type=coupon&p={$this->ID}");
			$wvcr->render('options-single', $this->data);
		}
	}
	
}

global $wvcr;

$wvcr->options = new wvcrOptions();


?>